package com.hjh.netty.elect.demo4;

import com.hjh.netty.elect.util.DataConvertUtils;
import com.hjh.netty.elect.util.NumberDataConvertUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 常用数据 (子类=0x01，版本=0)
 * @author pyz
 *
 */
@Service("analysisCommonlyUpLoadDataService")
public class AnalysisCommonlyUpLoadDataService implements AnalysisUpLoadDataService{
	
	@Override
	public SubType1TypeVer0 analysisUpLoadData(String upLoadData) {
		int index = 0;
		SubType1TypeVer0 result = new SubType1TypeVer0();
		//DI状态  格式：uint16，单位：
		String DIStatus = upLoadData.substring(index, index + 4);
		result.setDIStatus(NumberDataConvertUtils.hexString2decimalInt(DIStatus));
		index += 4;
		//DO状态  格式：uint16，单位：
		String DOStatus = upLoadData.substring(index, index + 4);
		result.setDOStatus(NumberDataConvertUtils.hexString2decimalInt(DOStatus));
		index += 4;
		//DI联动状态  格式：uint16，单位：
		String DILinkStatus = upLoadData.substring(index, index + 4);
		result.setDILinkStatus(NumberDataConvertUtils.hexString2decimalInt(DILinkStatus));
		index += 4;
		//剩余电流报警状态  格式：uint16，单位：
		String IRalarmStatus = upLoadData.substring(index, index + 4);
		result.setIRalarmStatus(NumberDataConvertUtils.hexString2decimalInt(IRalarmStatus));
		index += 4;
		//温度报警状态  格式：uint16，单位：
		String TCalarmStatus = upLoadData.substring(index, index + 4);
		result.setTCalarmStatus(NumberDataConvertUtils.hexString2decimalInt(TCalarmStatus));
		index += 4;
		//电流报警/预警状态  格式：uint16，单位：
		String IalarmStatus = upLoadData.substring(index, index + 4);
		result.setIalarmStatus(NumberDataConvertUtils.hexString2decimalInt(IalarmStatus));
		index += 4;
		//剩余电流自检状态  格式：uint16，单位：
		String IRCheckStatus = upLoadData.substring(index, index + 4);
		result.setIRCheckStatus(NumberDataConvertUtils.hexString2decimalInt(IRCheckStatus));
		index += 4;
		//温度自检状态  格式：uint16，单位：
		String TCCheckStatus = upLoadData.substring(index, index + 4);
		result.setTCCheckStatus(NumberDataConvertUtils.hexString2decimalInt(TCCheckStatus));
		index += 4;
		//总故障报警状态 格式：uint16，单位：
		String AllalarmStatus = upLoadData.substring(index, index + 4);
		result.setAllalarmStatus(NumberDataConvertUtils.hexString2decimalInt(AllalarmStatus));
		index += 4;
		//越限状态  格式：uint16，单位：
		String setpointStatus = upLoadData.substring(index, index + 4);
		result.setSetpointStatus(NumberDataConvertUtils.hexString2decimalInt(setpointStatus));
		index += 4;
		//自检状态  格式：uint16，单位：
		String selfCheckStatus = upLoadData.substring(index, index + 4);
		result.setSelfCheckStatus(NumberDataConvertUtils.hexString2decimalInt(selfCheckStatus));
		index += 4;
		//总正向有功电能  格式：int32，单位：0.01kWh
		String wirelessSignalIntensity = upLoadData.substring(index, index + 8);
		result.setWirelessSignalIntensity(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(wirelessSignalIntensity), new BigDecimal("0.01")));
		index += 8;
		//A 相正向有功电能  格式：int32，单位：0.01kWh
		String kWhImp1 = upLoadData.substring(index, index + 8);
		result.setKWhImp1(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(kWhImp1), new BigDecimal("0.01")));
		index += 8;
		//B 相正向有功电能  格式：int32，单位：0.01kWh
		String kWhImp2 = upLoadData.substring(index, index + 8);
		result.setKWhImp2(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(kWhImp2), new BigDecimal("0.01")));
		index += 8;
		//C 相正向有功电能  格式：int32，单位：0.01kWh
		String kWhImp3 = upLoadData.substring(index, index + 8);
		result.setKWhImp3(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(kWhImp3), new BigDecimal("0.01")));
		index += 8;
		//A相电流  格式：Uint32，单位：mA
		String I1 = upLoadData.substring(index, index + 8);
		result.setI1(NumberDataConvertUtils.hexString2decimalInt(I1));
		index += 8;
		//B相电流  格式：Uint32，单位：mA
		String I2 = upLoadData.substring(index, index + 8);
		result.setI2(NumberDataConvertUtils.hexString2decimalInt(I2));
		index += 8;
		//C相电流  格式：Uint32，单位：mA
		String I3 = upLoadData.substring(index, index + 8);
		result.setI3(NumberDataConvertUtils.hexString2decimalInt(I3));
		index += 8;
		//A相电压  格式：Uint32，单位：mV
		String U1 = upLoadData.substring(index, index + 8);
		result.setU1(NumberDataConvertUtils.hexString2decimalInt(U1));
		index += 8;
		//B相电压  格式：Uint32，单位：mV
		String U2 = upLoadData.substring(index, index + 8);
		result.setU2(NumberDataConvertUtils.hexString2decimalInt(U2));
		index += 8;
		//C相电压  格式：Uint32，单位：mV
		String U3 = upLoadData.substring(index, index + 8);
		result.setU3(NumberDataConvertUtils.hexString2decimalInt(U3));
		index += 8;
		//频率  格式：uint16，单位：
		String freq = upLoadData.substring(index, index + 4);
		result.setFreq(NumberDataConvertUtils.hexString2decimalInt(freq));
		index += 4;
		//总功率因数  格式：int16，单位：0.0001
		String PFavg = upLoadData.substring(index, index + 4);
		result.setKWhImp3(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(PFavg), new BigDecimal("0.0001")));
		index += 4;
		//A相有功功率  格式：int32，单位：0.01W
		String P1 = upLoadData.substring(index, index + 8);
		result.setP1(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(P1), new BigDecimal("0.01")));
		index += 8;
		//B相有功功率  格式：int32，单位：0.01W
		String P2 = upLoadData.substring(index, index + 8);
		result.setP2(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(P2), new BigDecimal("0.01")));
		index += 8;
		//C相有功功率  格式：int32，单位：0.01W
		String P3 = upLoadData.substring(index, index + 8);
		result.setP3(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(P3), new BigDecimal("0.01")));
		index += 8;
		//A相无功功率  格式：int32，单位：0.01var
		String Q1 = upLoadData.substring(index, index + 8);
		result.setQ1(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(Q1), new BigDecimal("0.01")));
		index += 8;
		//B相无功功率  格式：int32，单位：0.01var
		String Q2 = upLoadData.substring(index, index + 8);
		result.setQ2(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(Q2), new BigDecimal("0.01")));
		index += 8;
		//C相无功功率  格式：int32，单位：0.01var
		String Q3 = upLoadData.substring(index, index + 8);
		result.setQ3(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(Q3), new BigDecimal("0.01")));
		index += 8;
		//A相视在功率  格式：Uint32，单位： 0.01VA
		String S1 = upLoadData.substring(index, index + 8);
		result.setS1(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(S1), new BigDecimal("0.01")));
		index += 8;
		//B相视在功率  格式：Uint32，单位： 0.01VA
		String S2 = upLoadData.substring(index, index + 8);
		result.setS2(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(S2), new BigDecimal("0.01")));
		index += 8;
		//C相视在功率  格式：Uint32，单位： 0.01VA
		String S3 = upLoadData.substring(index, index + 8);
		result.setS3(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(S3), new BigDecimal("0.01")));
		index += 8;
		//三相总有功功率  格式：int32，单位：0.01W
		String P = upLoadData.substring(index, index + 8);
		result.setP(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(P), new BigDecimal("0.01")));
		index += 8;
		//三相总无功功率  格式：int32，单位：0.01var
		String Q = upLoadData.substring(index, index + 8);
		result.setQ(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(Q), new BigDecimal("0.01")));
		index += 8;
		//三相总视在功率  格式：Uint32，单位：0.01VA
		String S = upLoadData.substring(index, index + 8);
		result.setS(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(S), new BigDecimal("0.01")));
		index += 8;
		//A/AB电压相位  格式：uint16，单位：0.1°
		String U1Ang = upLoadData.substring(index, index + 4);
		result.setU1Ang(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(U1Ang), new BigDecimal("0.1")));
		index += 4;
		//B/BC电压相位  格式：uint16，单位：0.1°
		String Ang = upLoadData.substring(index, index + 4);
		result.setAng(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(Ang), new BigDecimal("0.1")));
		index += 4;
		//C/CA电压相位  格式：uint16，单位：0.1°
		String U3Ang = upLoadData.substring(index, index + 4);
		result.setU3Ang(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(U3Ang), new BigDecimal("0.1")));
		index += 4;
		//A相电流相位  格式：uint16，单位：0.1°
		String IaAng = upLoadData.substring(index, index + 4);
		result.setIaAng(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(IaAng), new BigDecimal("0.1")));
		index += 4;
		//B相电流相位  格式：uint16，单位：0.1°
		String IbAng = upLoadData.substring(index, index + 4);
		result.setIbAng(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(IbAng), new BigDecimal("0.1")));
		index += 4;
		//C相电流相位  格式：uint16，单位：0.1°
		String IcAng = upLoadData.substring(index, index + 4);
		result.setIcAng(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(IcAng), new BigDecimal("0.1")));
		index += 4;
		//电压不平衡度  格式：uint16，单位： 0.01%
		String UUnb = upLoadData.substring(index, index + 4);
		result.setUUnb(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(UUnb), new BigDecimal("0.01")));
		index += 4;
		//电流不平衡度  格式：uint16，单位： 0.01%
		String IUnb = upLoadData.substring(index, index + 4);
		result.setIUnb(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(IUnb), new BigDecimal("0.01")));
		index += 4;
		//A相电压总畸变率  格式：uint16，单位： 0.01%
		String U1THD = upLoadData.substring(index, index + 4);
		result.setU1THD(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(U1THD), new BigDecimal("0.01")));
		index += 4;
		//B相电压总畸变率  格式：uint16，单位： 0.01%
		String U2THD = upLoadData.substring(index, index + 4);
		result.setU2THD(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(U2THD), new BigDecimal("0.01")));
		index += 4;
		//C相电压总畸变率  格式：uint16，单位： 0.01%
		String U3THD = upLoadData.substring(index, index + 4);
		result.setU3THD(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(U3THD), new BigDecimal("0.01")));
		index += 4;
		//A相电流总畸变率  格式：uint16，单位： 0.01%
		String I1THD = upLoadData.substring(index, index + 4);
		result.setI1THD(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(I1THD), new BigDecimal("0.01")));
		index += 4;
		//B相电流总畸变率  格式：uint16，单位： 0.01%
		String I2THD = upLoadData.substring(index, index + 4);
		result.setI2THD(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(I2THD), new BigDecimal("0.01")));
		index += 4;
		//B相电流总畸变率  格式：uint16，单位： 0.01%
		String I3THD = upLoadData.substring(index, index + 4);
		result.setI3THD(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(I3THD), new BigDecimal("0.01")));
		index += 4;
		//温度 1  格式：int16，单位：0.1℃
		String TC1 = upLoadData.substring(index, index + 4);
		result.setTC1(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(TC1), new BigDecimal("0.1")));
		index += 4;
		//温度 2  格式：int16，单位：0.1℃
		String TC2 = upLoadData.substring(index, index + 4);
		result.setTC2(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(TC2), new BigDecimal("0.1")));
		index += 4;
		//温度 3 格式：int16，单位：0.1℃
		String TC3 = upLoadData.substring(index, index + 4);
		result.setTC3(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(TC3), new BigDecimal("0.1")));
		index += 4;
		//温度 4  格式：int16，单位：0.1℃
		String TC4 = upLoadData.substring(index, index + 4);
		result.setTC4(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(TC4), new BigDecimal("0.1")));
		index += 4;
		//剩余电流 IR 4  格式：Uint16，单位：0.1mA
		String IR = upLoadData.substring(index, index + 4);
		result.setIR(DataConvertUtils.converInt2Float(NumberDataConvertUtils.hexString2decimalInt(IR), new BigDecimal("0.1")));
		index += 4;
		
		return result;
	}

}
